package com.test;

/**
 * @Description:循环链表
 * @Auther: liuyanhui
 * @Date: 2024/03/12/ 15:12
 */
public class CircularLinkedList {
    private CircularListNode head;
    public void insert(int value) {
        CircularListNode node = new CircularListNode(value);
        if (head == null) {
            head = node;
            head.next = head;
        } else {
            CircularListNode temp = head;
            while (temp.next != head) {
                temp = temp.next;
            }
            temp.next = node;
            node.next = head;
        }
    }
    public void delete(int value) {
        if (head == null) {
            return;
        }
        if (head.value == value) {
            head = head.next;
        } else {
            CircularListNode temp = head;
            while (temp.next != head) {
                if (temp.next.value == value) {
                    temp.next = temp.next.next;
                    break;
                }
                temp = temp.next;
            }
        }
    }
}
